package front

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"qihuang/protocol"
	"qihuang/service/front"
	"strconv"
)

type Standards struct {
}

//文章列表
func (Standards) GetList(c *gin.Context) {
	resp := &protocol.Resp{Status: 0, Msg: "", Data: ""}
	page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
	if err != nil {
		page = 1
	}
	pageSize, err := strconv.Atoi(c.DefaultQuery("page_size", "10"))
	if err != nil {
		pageSize = 10
	}
	topicServ := front.Standards{}
	fields := []string{"id", "age", "key_name", "key_value", "modify_time", "create_time"}
	//resp = topicServ.GetListForEs(page, pageSize, fields)
	//if resp.Status == -999 {
	resp = topicServ.GetListForMysql(page, pageSize, fields)
	//}
	c.JSON(http.StatusOK, resp)
}

//文章详情
func (Standards) Show(c *gin.Context) {
	resp := &protocol.Resp{Status: 1, Msg: "", Data: ""}
	id, err := strconv.Atoi(c.Param("id"))
	topicServ := front.Standards{}
	if err != nil || id <= 0 {
		resp.Status = 1
		resp.Msg = "参数错误"
		c.JSON(http.StatusOK, resp)
		return
	}
	resp = topicServ.GetStandardDetail(id)
	c.JSON(http.StatusOK, resp)
}

////文章类型
//func (Topics) GetCategories(c *gin.Context) {
//	resp := &protocol.Resp{Status: 0, Msg: "", Data: ""}
//	articleServ := front.Articles{}
//	resp = articleServ.GetArticleCate()
//	c.JSON(http.StatusOK, resp)
//}
